package com.controller;

import com.entity.CatMsg;
import com.entity.CatUser;
import com.service.CatMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CatMsgController {

    @Autowired
    private CatMsgService CatMsgservice;

    @RequestMapping("/AllCatMsg")
    public List<CatMsg> getAllCatMsg(){return CatMsgservice.getAllCatMsg();}

    @RequestMapping("/AllCatMsgExam")
    public List<CatMsg> getAllCatMsgExam(){return CatMsgservice.getAllCatMsgExam();}

    @RequestMapping("/UserCatMsgPub")
    public List<CatMsg> getUserCatMsgPub(String username){
        List a = CatMsgservice.getUserCatMsgPub(username);
        return a;
    }

    @RequestMapping("/UserCatMsgExam")
    public List<CatMsg> getUserCatMsgExam(String username){
        List a = CatMsgservice.getUserCatMsgExam(username);
        return a;
    }

    @RequestMapping("/AddCat")
    public String AddCat(@RequestBody CatMsg catMsg){
        int i = CatMsgservice.AddCat(catMsg);
        return i > 0 ? "success" : "error";
    }

    @RequestMapping("/AddCatExam")
    public String AddCatExam(@RequestBody CatMsg catMsg){
        int i = CatMsgservice.AddCatExam(catMsg);
        return i > 0 ? "success" : "error";
    }

    @RequestMapping("/EditCat")
    public String EditCat(@RequestBody CatMsg catMsg){
        int i = CatMsgservice.EditCat(catMsg);
        return i > 0 ? "success" : "error";
    }

    @RequestMapping("/EditCatExam")
    public String EditCatExam(@RequestBody CatMsg catMsg){
        int i = CatMsgservice.EditCatExam(catMsg);
        return i > 0 ? "success" : "error";
    }

    @RequestMapping("/DelCat")
    public String DelCat( String ccatid){
        int i = CatMsgservice.DelCat(ccatid);
        return i > 0 ? "success" : "error";
    }

    @RequestMapping("/DelCatExam")
    public String DelCatExam(@RequestBody CatMsg catMsg){
        int i = CatMsgservice.DelCatExam(catMsg);
        return i > 0 ? "success" : "error";
    }
}
